<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('工单结算信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>创建时间：</label>
                                <input type="text" class="time-input" placeholder="请选择创建时间" name="createTime"/>
                            </li>
                            <li>
                                <label>订单号：</label>
                                <input type="text" name="orderId"/>
                            </li>
                            <li>
                                <label>费用分类：</label>
                                <select name="feeType" th:with="type=${@dict.getType('fee_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>费用类型：</label>
                                <select name="feeClassify" th:with="type=${@dict.getType('fee_classify')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <!--<div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="zsyh:serviceOrderSettlement:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="zsyh:serviceOrderSettlement:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="zsyh:serviceOrderSettlement:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="zsyh:serviceOrderSettlement:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>-->
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zsyh:serviceOrderSettlement:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zsyh:serviceOrderSettlement:remove')}]];
        var feeTypeDatas = [[${@dict.getType('fee_type')}]];
        var feeClassifyDatas = [[${@dict.getType('fee_classify')}]];
        var prefix = ctx + "zsyh/serviceOrderSettlement";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                modalName: "工单结算信息",
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '工单结算id',
                    visible: false
                },
                {
                    field: 'orderId',
                    align: 'center',
                    title: '订单号'
                },
                {
                    field: 'storeName',
                    align: 'center',
                    title: '店铺名称'
                },{
                    field: 'storePerson',
                    align: 'center',
                    title: '负责人'
                },{
                    field: 'storePhone',
                    align: 'center',
                    title: '联系方式'
                },
                {
                    field: 'factoryName',
                    align: 'center',
                    title: '结算厂家'
                },
                {
                    field: 'feeType',
                    align: 'center',
                    title: '费用分类',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(feeTypeDatas, value);
                    }
                },
                {
                    field: 'feeClassify',
                    align: 'center',
                    title: '费用类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(feeClassifyDatas, value);
                    }
                },
                {
                    field: 'feeMoney',
                    align: 'center',
                    title: '金额'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }],onLoadSuccess: function (res) {//当所有数据被加载时触发处理函数
                    var data = $('#bootstrap-table').bootstrapTable('getData', true);//获取当前页数据
                    mergeCells(data,'orderId',1,$('#bootstrap-table'));
                }
            };
            $.table.init(options);
        });


        /**
         * 合并单元格
         * @param data 原始数据（在服务端完成排序）
         * @param fieldName 合并属性名称
         * @param colspan 合并列
         * @param target 目标表格对象
         */
        function mergeCells(data,fieldName,colspan,target){
            //声明一个map计算相同属性值在data对象出现的次数和
            var sortMap = {};
            for(var i = 0 ; i < data.length ; i++){
                for(var prop in data[i]){
                    if(prop == fieldName){
                        var key = data[i][prop]
                        if(sortMap.hasOwnProperty(key)){
                            sortMap[key] = sortMap[key] * 1 + 1;
                        } else {
                            sortMap[key] = 1;
                        }
                        break;
                    }
                }
            }
            for(var prop in sortMap){
                console.log(prop,sortMap[prop])
            }
            var index = 0;
            for(var prop in sortMap){
                var count = sortMap[prop] * 1;
                $(target).bootstrapTable('mergeCells',{index:index, field:fieldName, colspan: colspan, rowspan: count});
                index += count;
            }
        }


    </script>
</body>
</html>